<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class AjaxController extends Controller
{

    public function getIndex(Request $request)
    {
        // 邮箱ajax
        $s = DB::table('shop_user') ->lists('email');
        $res = in_array($_GET['email'], $s);
        if($res){
            return 1;
        }else{
            return 2;
        }
    }


    public function getCode()
    {
        // 邮箱的验证码
        return session('code');
    }


       public function getIndex2(Request $request)
    {
        // 手机用户的ajax
        $s = DB::table('shop_user') ->lists('tel');
        $res = in_array($_GET['tel'], $s);
        if($res){
            return 1;
        }else{
            return 2;
        }
    }

    public function getCode2()
    {
        // 手机号的验证码
        return session('phone_code');
    }
    

}
/**
    *ajax验证某表中的某字段的值是否已存在
    *
    *@$request Request  接受数据的对象
    */
    public function getVerify(Request $request)
    {
        //获取查询表中要搜索字段的值
        $table = $request ->input('table');
        $list = $request ->input('list');
        $arr = DB::table($table) ->lists($list);
        //获取要判断的值
        $value = $request ->input($list);
        //判断值在表中是否已存在
        $res = in_array($value, $arr);
        if($res)
            echo 1;
    }